// Copyright 2008 Thiago H. de Paula Figueiredo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package br.com.arsmachina.tapestrycrud.hibernatevalidator.ioc;

import java.util.Map;

import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.services.LibraryMapping;
import org.hibernate.validator.ClassValidator;

import br.com.arsmachina.tapestrycrud.hibernatevalidator.services.ClassValidatorSource;
import br.com.arsmachina.tapestrycrud.hibernatevalidator.services.impl.ClassValidatorSourceImpl;

/**
 * Tapestry-IoC module for tapestry-crud-hibernate-validator.
 * 
 * @author Thiago H. de Paula Figueiredo
 */
public class TapestryCrudHibernateValidatorModule {

	/**
	 * Builds the {@link ClassValidatorSource} service.
	 * 
	 * @param contributions a {@link Map<Class, ClassValidator>}.
	 * @return an {@link ClassValidatorSource}.
	 */
	@SuppressWarnings("unchecked")
	public static ClassValidatorSource buildClassValidatorSource(
			Map<Class, ClassValidator> contributions) {
		return new ClassValidatorSourceImpl(contributions);
	}

	/**
	 * Contributes the tapestry-crud components under the <code>crud</code> prefix.
	 * 
	 * @param configuration a {@link Configuration}.
	 */
	public static void contributeComponentClassResolver(Configuration<LibraryMapping> configuration) {

		configuration.add(new LibraryMapping("crudhv",
				"br.com.arsmachina.tapestrycrud.hibernatevalidator"));

	}

}
